package com.example.study.testcomparable;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

/**
 * 测试类
 *
 * @author hjh
 * @create 2019-08-22 0:36
 **/
public class Test {
    public static void main(String[] args) {
        Person person1 = new Person(11,"77");
        Person person2 = new Person(88,"44");
        Person person3 = new Person(22,"66");
        List<Person> personList = new ArrayList<>();
        personList.add(person1);
        personList.add(person2);
        personList.add(person3);
        Collections.sort(personList, new Comparator<Person>() {
            @Override
            public int compare(Person o1, Person o2) {
                return o1.getAge()-o2.getAge();
            }
        });
        System.out.println(personList);
    }
}
